import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lcapp/api/interface/user_api.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/basic/user_info.dart';
import 'package:lcapp/data/user_data_entity.dart';
import 'package:lcapp/model/refresh/refresh.dart';
import 'package:lcapp/page/search/search_user_item.dart';

class FansFollowsListPage extends StatefulWidget {
  final int type; //0意向 1粉丝 2关注
  const FansFollowsListPage({Key? key, required this.type}) : super(key: key);

  @override
  _FansFollowsListPageState createState() => _FansFollowsListPageState();
}

class _FansFollowsListPageState extends State<FansFollowsListPage> {

  List<UserDataEntity> users = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getUsers();
  }

  getUsers()async{
    late ResponseData res;
    if(widget.type==0){
      res = await UserAPI.getMinYixiang(1,10000,userInfo.id!);
    }else if(widget.type==1){
      res = await UserAPI.getMinFans();
    }else if(widget.type==2){
      res = await UserAPI.getMinFollows();
    }
    if(res.code==200){
      users.clear();
      List arr = res.data??[];
      for (var element in arr) {
        UserDataEntity entity = UserDataEntity().fromJson(element);
        entity.attentionState = element['state']??0;
        users.add(entity);
      }
    }
    if(mounted){setState(() {
    });}
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 30.w),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.symmetric(vertical: 30.w),
            child: Row(
              children: [
                Container(width: 5,height: 34.sp,color: Color(0xffFF7916),),
                SizedBox(width: 20.w,),
                Text(widget.type==0? '意向用户':widget.type==1?'我的粉丝':'我的关注',style: TextStyle(
                    color: Colors.black,
                    fontWeight: FontWeight.w700,
                    fontSize: 34.sp
                ),),
              ],
            ),
          ),
          Expanded(child: EasyRefresh(
            header: myRefreshHeader(),
            onRefresh: ()async{
              getUsers();
            },
            child: ListView.builder(
                padding: EdgeInsets.zero,
                shrinkWrap: true,
                itemCount: users.length,
                itemBuilder: (BuildContext context, int i) {
                  return SearchUserItem(entity: users[i],cilickFun: (){
                    Navigator.of(context).pushNamed("ShopHomePage",arguments: users[i].id).then((value){
                      getUsers();
                    });
                  },);
                }),
          )),
        ],
      ),
    );
  }
}
